from Bio import GenBank
import sys

search_words = 'Fenneropenaeus AND chinensis'

td = 'fc'
step = 10
i = 0

while True:
    try:
        #print i
        
        gis = GenBank.search_for(search_words, start_id=i, max_ids=step)
        if not gis:break

        r = GenBank.download_many(gis)

        ofn = '%s/%s.txt'%(td, str(i), 'w')
        open(ofn,'w').write(r.getvalue())
        
        i = i + step
        break
        
    except KeyboardInterrupt:
        print 'I am quiting'
        break

    except :
    	print 'Exception:', sys.exc_info()[1], '\n'
        

